package com.koron.operation.classes.form.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.operation.classes.form.bean.po.ClassesFormRecord;
import com.koron.operation.classes.form.bean.query.ClassesFormRecordQuery;
import com.koron.operation.classes.form.bean.vo.ClassesFormRecordVO;
import com.koron.operation.classes.form.service.ClassesFormRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 月度排班打卡记录表(ClassesFormRecord)表控制层
 *
 * @author jzp
 * @since 2023-05-19 10:27:45
 */
@Api(tags = "月度排班打卡记录表接口")
@RestController
@RequestMapping("classesFormRecord")
public class ClassesFormRecordController {
    /**
     * 服务对象
     */
    @Autowired
    private ClassesFormRecordService classesFormRecordService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "分页")
    @GetMapping("pageRecord")
    public Response<PageInfo<ClassesFormRecordVO>> pageRecord(PageQuery pageQuery, ClassesFormRecordQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesFormRecordService, "pageVo", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "列表查询")
    @GetMapping("list")
    public Response<List<ClassesFormRecord>> list(ClassesFormRecord classesFormRecord) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesFormRecordService, "list", List.class, classesFormRecord));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<ClassesFormRecord> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesFormRecordService, "getById", ClassesFormRecord.class, id));
    }

    @ApiOperation(value = "保存或更新数据")
    @PostMapping
    public Response<ClassesFormRecord> save(@RequestBody ClassesFormRecord classesFormRecord) {
        ADOConnection.runTask(getCurrDs(), classesFormRecordService, "save", Boolean.class, classesFormRecord);
        return Response.ok(classesFormRecord);
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping
    public Response<String> delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), classesFormRecordService, "deleteById", Boolean.class, id);
        return Response.ok();
    }

}

